/*******************************************************************************
 *  InputElement class
 *******************************************************************************

// example options object
var options = {
    id: 'id',
    name: 'name',
    type: 'text',
    placeholder: 'placeholder',   
    classes: 'classes',
    value: 'value',
    disabled: false,
    rules:{
        // validation rules here
        messages: {
            // validation messages here
        }
    }
}

*/

/**
 *  Represent input model
 */
var InputElement = function(options) {
    
    // this class should extend an Element class
    $.extend(true, this, new Element($('<input>')))
    this.getElement()[0].wrapper = this;
    // ------------------------------------------------------- settings
    this.defaults = {
        name: options.id,
        type: 'text'
    };
    
    var settings = this.prepareSettings(options);
    
    // ------------------------------------------------------- methods
    
    /**
     *  Sets value
     *  @param value
     *  @return class instance
     */
    this.setValue = function(value){
        this.getElement().val(value);
        return this;
    }
    
    // ------------------------------------------------------- element creation
    this.setId(settings.id)
        .addAttribute('name', settings.name)
        .addAttribute('type', settings.type)
        .addClass(settings.classes)
        .addAttribute('placeholder', settings.placeholder)
        .setValue(settings.value);
        
    if(settings.disabled) this.disable();
        
    // prepares element validation
        if(settings.rules){
            var metaobject = {
                validate: settings.rules
            };

            var metadata = JSON.stringify(metaobject);
            console.log(metadata);
            this.addClass(metadata)
        }
    
    console.log('InputElement was created with id = '+this.getId());
}